package com.java.basic;

public class ThreadLocalTest {

    public static void main(String[] args){
        ThreadLocal tl = new ThreadLocal();
        ThreadLocal t2 = new ThreadLocal();
        final Thread thread1 = new Thread(()->{
            String str = "zangsan";
            System.out.println("当前线程:"+Thread.currentThread().getName()+"-->"+str);
            tl.set(str);
            for(int i=0;i<20;i++){
                t2.set(i+"*"+str+"-->"+i);
            }

            System.out.println("当前线程:"+Thread.currentThread().getName()+"-->"+tl.get());
            System.out.println("当前线程:"+Thread.currentThread().getName()+"-->"+t2.get());
        },"线程1");
        /*final Thread thread2 = new Thread(()->{
            try {
                thread1.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            String str = "lisi";
            System.out.println("当前线程:"+Thread.currentThread().getName()+"-->"+str);
            tl.set(str);
            System.out.println("当前线程:"+Thread.currentThread().getName()+"-->"+tl.get());
        },"线程2");
        final Thread thread3 = new Thread(()->{
            try {
                thread2.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            String str = "王五";
            System.out.println("当前线程:"+Thread.currentThread().getName()+"-->"+str);
            tl.set(str);
            System.out.println("当前线程:"+Thread.currentThread().getName()+"-->"+tl.get());
        },"线程3");*/

        thread1.start();
        tl.remove();
        t2.remove();
       /* thread2.start();
        thread3.start();*/
    }
}
